<?php
namespace Apipad\Controller;
use Think\Controller;

class UserKuerpWarehouseOrdersController extends CommonController{

    //规格信息
    function detail_list(){
        $model = D('UserKuerpWarehouseLog');
        if(!I('id')){
            $this->ajaxErrReturn('id必须');
        }
        $wdata['order_id'] = I('id');
        $list = $model->where($wdata)->select();
        $this->ajaxSucReturn($list);
    }

    //删除
    function vdel(){
        $model = D('UserKuerpWarehouseLog');
        if(!I('id')){
            $this->ajaxErrReturn('id必须');
        }
        $o_model = M('UserKuerpWarehouseOrders');
        $o_model->startTrans();
        $o_wdata['id'] = I('id');
        $o_vo = $o_model->where($o_wdata)->lock(true)->find();
        if(!$o_vo){
            $this->ajaxErrReturn('订单不存在');
        }
        if($o_vo['is_delete']==1){
            $this->ajaxErrReturn('订单已删除');
        }
        $wdata['order_id'] = I('id');
        $list = $model->where($wdata)->select();
        foreach($list as $val){
            $res = $model->revert($val);
            if(!$res['status']){
                $this->ajaxErrReturn($res['msg']);
            }
            //dump($res);
        }
        $o_sdata['is_delete'] = 1;
        $res = $o_model->where($o_wdata)->save($o_sdata);
        if(!$res){
            $this->ajaxErrReturn('删除失败');
        }
        //dump(1);exit;
        $o_model->commit();
        $this->ajaxSucReturn('删除成功');
    }

}